// 测试会不会真的抛错
// 这里推荐一篇关于promise的博客: https://juejin.im/post/5e58c618e51d4526ed66b5cf?utm_source=gold_browser_extension#heading-16
fetch = () => new Promise((resolve, reject) => {
  setTimeout(() => {
    console.log('fetch')
    reject(1) 
  }, 1000)
})

action = () => new Promise((resolve, reject) => {
  fetch().then(resolve, reject)
}).then(res => {
  console.log(2, JSON.stringify({ res }))
}).catch(error => {
  return {
    code: 7000,
    error
  }
})


function test() {
  action().then(res=> console.log('陈工', res), err => console.log('报错', err)).catch(err => console.log('in catch'))
}

test() // fetch CR; 陈工 { code: 7000, error: 1 }

// 结果发现不会抛出错误

// async function test2() {
//   const res = await Promise.resolve(2).then(res => res * 2)
//   console.log(res)
// }
// test2() // 2